#ifndef WEB_SOCK_HOLDER_H_INCLUDED
#define WEB_SOCK_HOLDER_H_INCLUDED

#include "st_sock_holder.h"
#include "http_request.h"
#include "http_response.h"
#include "http_servlet_container.h"
#include <string>
using std::string;

namespace vmon_web
{
    class HttpServlet;

    class WebSockHolder: public STSockHolder
    {
    public:
        WebSockHolder(int sock, HttpServletContainer& servletContainer);
        virtual ~WebSockHolder();
        virtual bool pushByte(char byte);
        virtual bool pushEnd();
        virtual bool handleRequest(HttpRequest& m_request);
        virtual bool send404(HttpRequest& m_request);
		virtual HttpRequest& getRequest() { return m_request; }
		virtual HttpResponse& getResponse() { return m_response; }
    private:
        enum State
        {
            GETTING_COMMAND,
            GETTING_PATH_PRE,
            GETTING_PATH,
            GETTING_VERSION_PRE,
            GETTING_VERSION,
            GETTING_HEADER_KEY,
            GETTING_HEADER_PRE_VALUE,
            GETTING_HEADER_VALUE,
            GOT_R,
            GOT_N,
            GOT_2ND_R,
            GETTING_BODY,
            DONE,
            ERROR_STATE
        } m_state;
        bool gotoState(State state);
        string m_line;
        string m_key;
        HttpRequest m_request;
        HttpResponse m_response;
        HttpServletContainer& m_servletContainer;
    };
}


#endif // WEB_SOCK_HOLDER_H_INCLUDED
